﻿@{
    Layout = null;
}
@model EnterpriseFund.Model.SupportPolicy
           
<!DOCTYPE html>

<html>
<head>
    <title>政策编辑</title>
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />
    <style>
        select{width:100%}
        input.txt,textarea{ width:99%; border:1px solid #aecaf0;}
        input.txt:focus,textarea:focus{border-color:#6e90be;}
        textarea{ height:70px;}
        input.btn{ width:50px;}
        .readonly{ background:#ccc;}
        /**/.hid{ display:none;}
        th{ text-align:right;}
        input.btn{ padding:3px;border:#a3c0e8 1px solid; background:#e2f0ff url(/EnterpriseFund/DXR.axd?r=0_54) repeat-x 50% top;color:#2c4d79; cursor:pointer; }
input.btn:hover{background-image:url(/EnterpriseFund/DXR.axd?r=0_57)}
    </style>
    
    @Html.DevExpress().GetStyleSheets(
        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>
 
<script>

    function checkRate() {
        var x = IsEvalBase.GetValue();
        if (x) {
            var rate1 = document.getElementById('rate1').value;
            var rate2 = document.getElementById('rate2').value;
            if (isEmpty(rate1) || !isNumeric(rate1) || isEmpty(rate2) || !isNumeric(rate2)) {
                alert('请正确输入补贴率！');
                return false;
            }
            if (rate1 * 1 > 100 || rate2 * 1 > 100) {
                alert('您补贴的太多了！');
                return false;
            }
        }
        else {
            var rates = document.getElementById('rates').value;
            if (isEmpty(rates)) {
                alert('请输入补贴率！');
                return false;
            }
            if (!isNumeric(rates)) {
                alert('请正确输入补贴率！');
                return false;
            }
//            var arr = rates.split(',');
//            for (var i = 0; i < arr.length; i++) {
//                if (isEmpty(arr[i]) || !isNumeric(arr[i])) {
//                    alert('请正确输入补贴率！');
//                    return false;
//                }
//            }
        }
        return true;
    }

    function checkAll() {
        if (FEnterprisePropNo.GetValue() == null) {
            alert('请选择企业性质！');
            return false;
        }
        if (FTaxClassAllowanceNo.GetValue() == null) {
            alert('请选择税种！');
            return false;
        }
        if ($('#ruleDesc').val() == '') {
            alert('请输入条件描述！');
            return false;
        }
        if ($('#ruleFormula').val() == '') {
            alert('请生成条件公式！');
            return false;
        }
        if(!checkRate()){
            return false;
        }
        if ($('#computeDesc').val() == '') {
            alert('请输入计算公式描述！');
            return false;
        }
        if ($('#cumputeFormula').val() == '') {
            alert('请生成计算公式！');
            return false;
        }
        if (FProp.GetValue() == null) {
            alert('请选择政策类型！');
            return false;
        }
        return true;
    }

    function showWindow(name) {
        $("#popContent").attr("src", name + "?x=" + Math.random());
        pop.Show();
    }

    function showRate() {
        var x = IsEvalBase.GetValue(); 
        show('div_rate1', x);
        show('div_rate2', !x);
    }

    function show(id, e) {
        document.getElementById(id).style.display = e ? 'block' : 'none';
    }

    function popHide() {
        pop.Hide();
    }

    function MenuTop_emClick(source, e) {
        var href =  '@Url.Content("~/SupportPolicy/")';
        switch (e.item.name) {
            case "btnSave":
                {
                    if (checkAll()) {

                        if($('#policyName').val() == '')$('#policyName').val($('#ruleDesc').val());

                        $('#rateInner').val($('#rate1').val() / 100);
                        $('#rateOuter').val($('#rate2').val() / 100);
                        if($('#rates').val())$('#rateOuter').val($('#rates').val() / 100);
                        
                        $('#cumputeExpression').val($('#cumputeExpression').val().replace(/"/g, ''));
                        $('#ruleExpression').val($('#ruleExpression').val().replace(/"/g, ''));

                        var url = '@Url.Content("~/SupportPolicy/save")';
                        $.post(url, $('#supportPolicy').serialize(), function (data) {
                            if (data) {
                                alert("保存成功！");
                            }
                            else { alert("保存失败！"); }
                            window.location.href = href;
                        });
                    }
                    break;
                }
            case "btnCancel":
                {
                    window.location.href = href;
                    break;
                }
        }
    }
</script>

</head>
<body>
<form action="@Url.Content("~/SupportPolicy/save")" method="post" id="supportPolicy">
 <div class="floatToolMenu" id="toolMenu">
        @Html.DevExpress().Menu(settings =>
   {
       settings.Name = "toolBarMenu";
       settings.ItemAutoWidth = false;
       settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
       settings.Styles.Style.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
       settings.Styles.Style.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
       settings.Items.Add(item =>
       {
           item.Name = "btnSave";
           item.Text = "保存";
           item.ClientEnabled = true;
           item.Image.Url = Url.Content("~/Content/ControlImages/filesave.png");

       });
       settings.Items.Add(item =>
       {
           item.Name = "btnCancel";
           item.Text = "取消";
           item.ClientEnabled = true;
           item.Image.Url = Url.Content("~/Content/ControlImages/no.png");

       });
       settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
       settings.ItemLinkMode = ItemLinkMode.ContentBounds;
   }).GetHtml()
   </div>

<input type="hidden" name="FPolicyID" value="@Model.FPolicyID" />
<input type="hidden" name="FInsEmpNo" value="@Model.FInsEmpNo" />
<input type="hidden" name="FInsDeptNo" value="@Model.FInsDeptNo" />
<input type="hidden" name="FInsIP" value="@Model.FInsIP" />
<input type="hidden" name="FInsDate" value="@Model.FInsDate" />
<input type="hidden" id="rateInner" name="FInnerRate" value="@Model.FInnerRate" />
<input type="hidden" id="rateOuter" name="FOuterRate" value="@Model.FOuterRate" />

<table cellpadding="2" width="700" border="0" >
    <tr>
        <th width="100">年度：</th>
        <td><input name="FYear" value="@Model.FYear" class="txt" readonly="readonly" /></td>
        
        <th>类型：</th>
        <td> @Html.DevExpress().ComboBox(settings =>
           {
               settings.Name = "FProp";
               settings.Properties.Items.Add("普通政策", "1");
               settings.Properties.Items.Add("特殊政策", "2");
               settings.Width = System.Web.UI.WebControls.Unit.Percentage(99);
           }).Bind(@Model.FProp).GetHtml()        
        </td>
    </tr>
    <tr>
        <th>企业性质：</th>
        <td>
            @Html.DevExpress().ComboBox(settings =>
           {
               settings.Name = "FEnterprisePropNo";
               settings.Properties.TextField = "FEnterprisePropName";
               settings.Properties.ValueField = "FEnterprisePropNo";
               settings.Width = System.Web.UI.WebControls.Unit.Percentage(99);
           }).BindList(ViewBag.EnterpriseProps).Bind(@Model.FEnterprisePropNo).GetHtml()        
        </td>
        <th>补贴税种：</th>
        <td>   
            @Html.DevExpress().ComboBox(settings =>
           {
               settings.Name = "FTaxClassAllowanceNo";
               settings.Properties.TextField = "FTaxClassAllowanceName";
               settings.Properties.ValueField = "FTaxClassAllowanceNo";
               settings.Width = System.Web.UI.WebControls.Unit.Percentage(99);
           }).BindList(ViewBag.TaxClassAllowance).Bind(@Model.FTaxClassAllowanceNo).GetHtml()
        </td>
    </tr>
    <tr>
        <th>条件描述：</th>
        <td colspan="3"><textarea name="FRuleDesc" id="ruleDesc" >@Model.FRuleDesc</textarea>
        </td>
    </tr>
    <tr>
        <th>政策名称：</th>
        <td colspan="3"><input name="FPolicyName" id="policyName" class="txt" value="@Model.FPolicyName" />
        </td>
    </tr>
    <tr>
        <th>条件公式：<br /><br />
            <input type="button" class="btn"  value="编辑" onclick="showWindow('@Url.Content("~/SupportPolicy/RuleFormula")');"  >
        </th>
        <td colspan="3">
            <textarea name="FRuleFormula" id="ruleFormula" readonly="readonly" class="readonly" >@Model.FRuleFormula</textarea>
            <textarea name="FRuleExpression" id="ruleExpression" readonly="readonly" class="hid">@Model.FRuleExpression</textarea>
             
        </td>
    </tr>
    <tr>
        <th height="100">补贴率（%）：</th>
        <td colspan="3">

            @Html.DevExpress().CheckBox(settings => {
           settings.Name = "IsEvalBase";
           settings.Text = "有基数";
           settings.Properties.ClientSideEvents.CheckedChanged = "showRate";
       }).Bind(@Model.IsEvalBase).GetHtml()

            <span id="div_rate1" style="display:none;">
                基数内补贴率：<input id="rate1" class="txt" style="width:31%"  />
                &nbsp; &nbsp; &nbsp; &nbsp;基数外补贴率(补贴率)：
                <input id="rate2" class="txt" style="width:31%"  />
            </span>
            <span id="div_rate2">
                补贴率：<input id="rates" class="txt" style="width:90%" />
            </span>            
            
            
        </td>
    </tr>
    <tr>
        <th>计算公式描述：</th>
        <td colspan="3"><textarea name="FComputeDesc" id="computeDesc" >@Model.FComputeDesc</textarea></td>
    </tr>
    <tr>
        <th align="right">计算公式：<br /><br />
        <input type="button" class="btn"  value="编辑" onclick="if(checkRate())showWindow('@Url.Content("~/SupportPolicy/ComputeFormula")');"  >
        </th>
        <td colspan="3">
            <textarea name="FComputeFormula" id="cumputeFormula" readonly="readonly"  class="readonly" >@Model.FComputeFormula</textarea>
            <textarea name="FComputeExpression" id="cumputeExpression" readonly="readonly" class="hid">@Model.FComputeExpression</textarea>
        
        </td>
    </tr>
    <tr>
        <th>备注：</th>
        <td colspan="3"><input name="FNote" value="@Model.FNote" class="txt" /></td>
    </tr>
</table>
</form>
@Html.DevExpress().PopupControl(
    settings =>
    {
        settings.Name = "pop";
        settings.Width = 550;
        settings.Height = 350;
        settings.AllowDragging = true;
        settings.CloseAction = CloseAction.CloseButton;
        settings.EnableAnimation = false;
        settings.HeaderText = "公式生成";
        settings.Modal = true;
        settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
        settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
        settings.SetContent(() =>
       {
           ViewContext.Writer.Write("<iframe  id='popContent' name='popContent' style='width:100%;height:320px' frameborder='0' ></iframe>");
       });
    }).GetHtml()
</body>
</html>

<script src="@Url.Content("~/Scripts/checkinput.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>

<script>

    $(function () {
        $("#toolMenu").smartFloat();
        showRate();

        $('#rate1').val(Math.round($('#rateInner').val() * 100));
        $('#rate2').val(Math.round($('#rateOuter').val() * 100));
        $('#rates').val(Math.round($('#rateOuter').val() * 100));
    });

</script>
